<?php
   // Edit upload location here
   include('../runid.php');
   $result = 0;
   $destination_path = getcwd().DIRECTORY_SEPARATOR;
   $filename = "";
   
   if ($_FILES["myfile"]["type"] == 'image/gif'  || $_FILES["myfile"]["type"] == 'image/pjpeg')
   {
   //$target_path = $destination_path ."files/". basename( $_FILES['myfile']['name']);
   $target_path = $destination_path ."files/";
   
   $ftype = explode(".",$_FILES['myfile']['name']);
   $filetype = $ftype[sizeof($ftype)-1];
   $filename = getImageName().".".$filetype;
   
	   if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path.$filename)) {
		  $result = 1;
		  $msg = "The file was uploaded successfully!";
	   }else{
	   		$result = 0;
			$msg = "There was an error during file upload!";
		}
   }
   else
   {
   		$msg = "ประเภทไฟล์ไม่ถูกต้องครับ ";
		echo $msg;
   }
   
   sleep(1);
?>

<script language="javascript" type="text/javascript">window.top.window.stopUpload(<?php echo $result.",'".$filename."','".$msg."'"; ?>);</script>   
